package com.yc.controller;

import com.yc.entity.StockEntity;
import com.yc.service.StockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.cloud.client.discovery.DiscoveryClient;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yangc91@bngrp.com
 * @date 2020/8/5 15:50
 */
@RestController
@Slf4j
public class ComputeController {
    @Autowired
    private DiscoveryClient client;
    @Autowired
    private StockService stockService;
    @Value("${server.port}")
    private Integer port;
    @RequestMapping(value = "/add" ,method = RequestMethod.GET )
    public Map<String,Object> add(@RequestParam Integer a, @RequestParam Integer b) {
        Map<String,Object> result=new HashMap<>();
        log.error("调用接口端口:{}",port);
        Integer r = a + b;
        result.put("add",r);
        System.out.println(1/0);
        return result;
    }
    @GetMapping(value = "/get")
    public StockEntity getByStockById(@RequestParam Integer id){
        return stockService.getByStockById(id);
    }
    @PostMapping(value = "/update")
    public String updateStockById( @RequestParam Long id){
        return stockService.updateStockById(id);
    }
}
